package com.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wms.entity.WUser;
import com.wms.entity.WUserStore;
import com.wms.dao.WUserStoreDao;
import com.wms.mytool.Result;
import com.wms.service.WUserStoreService;
import com.wms.vo.WUserStoreInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 用户-仓库权限表(WUserStore)表服务实现类
 *
 * @author makejava
 * @since 2023-10-20 17:21:21
 */
@Service("wUserStoreService")
public class WUserStoreServiceImpl implements WUserStoreService {
    @Resource
    private WUserStoreDao wUserStoreDao;

    /**
     * 查询所有
     * @return 实例对象
     */
    @Override
    public Result selectAll() {
        List<WUserStoreInfo> userStoreInfos = this.wUserStoreDao.selectUserStoreInfo();
        return new Result(200,userStoreInfos,"查询成功");
    }

    /**
     * 根据用户id查询仓库权限
     * @return 实例对象
     */
    @Override
    public Result selectByUid(Integer id) {
        List<WUserStoreInfo> infos = this.wUserStoreDao.selectByUserId(id);
        return new Result(200,infos,"查询成功");
    }

    /**
     * 添加仓库权限
     * @param wUserStore 仓库权限信息
     * @return 实例对象
     */
    @Override
    public Result addWUserStore(WUserStore wUserStore) {
        wUserStore.setCreateTime(new Date());
        wUserStore.setUpdateTime(new Date());
        int i = this.wUserStoreDao.insert(wUserStore);
        if(i==1){
            return new Result(200,i,"添加成功");
        }else{
            return new Result(400,null,"添加失败");
        }
    }

    /**
     * 修改仓库权限信息
     * @param wUserStore 仓库权限信息
     * @return 实例对象
     */
    @Override
    public Result updateWUserStore(WUserStore wUserStore) {
        int i = this.wUserStoreDao.updateById(wUserStore);
        if(i==1){
            return new Result(200,i,"修改成功");
        }else{
            return new Result(400,null,"修改失败");
        }
    }

    @Override
    public Result updateByVo(WUserStoreInfo wUserStoreInfo) {
        wUserStoreInfo.setUpdateTime(new Date());
        int i = this.wUserStoreDao.updateByVo(wUserStoreInfo);
        if(i==1){
            return new Result(200,i,"修改成功");
        }else{
            return new Result(400,null,"修改失败");
        }
    }

    /**
     * 删除仓库权限信息
     * @param id 仓库权限id
     * @return 实例对象
     */
    @Override
    public Result deleteWUserStore(Integer id) {
        QueryWrapper<WUserStore> qw = Wrappers.query();
        qw.eq("id", id);
        int i = this.wUserStoreDao.delete(qw);
        if(i==1){
            return new Result(200,i,"删除成功");
        }else{
            return new Result(400,null,"删除失败");
        }

    }
}
